home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / oath.lha / oath / src / character.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-08  |  5.4 KB  |  168 lines

  1. //***************************************************************************
  2. //             OATH :: Object-oriented Abstract Type Hierarchy
  3. //***************************************************************************
  4. //
  5. //  Copyright (C) 1991, 1990  Texas Instruments Incorporated
  6. //  Permission is granted to any individual or institution
  7. //  to use, copy, modify, and distribute this software,
  8. //  provided that this complete copyright and permission notice
  9. //  is maintained, intact, in all copies and supporting documentation.
  10. //
  11. //  Texas Instruments Incorporated provides this software "as is"
  12. //  without express or implied warranty.
  13. //
  14. //***************************************************************************
  15. //  character (characterA, characterG)
  16. //
  17. //  History:
  18. //    06/92  Brian M Kennedy  Made TheCharacters array a non-member (porting)
  19. //    07/91  Brian M Kennedy  import, export, typeRegister
  20. //    06/91  Brian M Kennedy  New macros & format; remove printDiagnostic
  21. //    10/90  Brian M Kennedy  Major Rewrite
  22. //    02/90  Brian M Kennedy  Original
  23. //
  24. //***************************************************************************
  25.  
  26. #include "copyright.h"
  27.  
  28. #include <oath/character.h>
  29.  
  30. #include <iostream.h>
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Character Outline Definitions
  34.  
  35. OUTLINES(character, token)
  36.  
  37. // Constructors //////////
  38.  
  39.     characterG::
  40. characterG ()  // Constructs a new characterG corresponding to the next char
  41.    :tokenG(), Value(Count++)
  42.    {ensure(!AllConstructed, "More than 256 characterLT's constructed!");
  43.     if(!Count)
  44.     AllConstructed = TRUE;
  45.     ValueToCharacters[Value] = this;
  46.     ref();
  47.    }
  48.  
  49.  
  50.     static const characterG
  51. TheCharacters [OATH_CHAR_CNT];
  52. // Instantiation of this array creates 256 characterG objects via the
  53. // default constructor above.  The default constructor should only be 
  54. // called by this array instantiation.  It cycles through the 256
  55. // values, instantiating each characterG to the next char value.  Each
  56. // characterG is then placed in the proper position in the array
  57. // ValueToCharacters so that it can be found by characterA::make.
  58. // If C++ compilers supported more sophisticated array initialization,
  59. // then this ugliness would be unnecessary.
  60.  
  61.  
  62.     characterG::
  63. ~characterG ()
  64.    {}
  65.  
  66.  
  67. // oathCore Operations //////////
  68.  
  69.     void characterG::
  70. export (exportP& X) const
  71.    {X.writeType(TypeName);
  72.     X.stream().put(value());
  73.    }
  74.  
  75.     objA characterG::
  76. import (importP& M)
  77.    {return ValueToCharacters[M.stream().get()];}
  78.  
  79.  
  80. // Other Operations //////////
  81.  
  82.     ostream&
  83. operator << (ostream& F, const characterA& C)
  84.    {return F << C.value();}
  85.  
  86.     istream&
  87. operator >> (istream& F, characterA& C)
  88.    {unsigned char Temp;
  89.     F >> Temp;
  90.     C = characterA::make(Temp);
  91.     return F;
  92.    }
  93.  
  94.  
  95. // Members //////////
  96.  
  97.     unsigned char
  98. characterG::Count = 0;
  99.  
  100.     int           // TRUE if 256 characters constructed
  101. characterG::AllConstructed = FALSE;
  102.  
  103.     const char *
  104. characterG::CharacterNames[OATH_CHAR_CNT] =
  105.  
  106.    {"Nul",  "Soh",  "Stx",  "Etx",  "Eot",  "Enq",  "Ack",  "Bel",
  107.     "Bs",   "Ht",   "Nl",   "Vt",   "Np",   "Cr",   "So",   "Si",
  108.     "Dle",  "Dc1",  "Dc2",  "Dc3",  "Dc4",  "Nak",  "Syn",  "Etb",
  109.     "Can",  "Em",   "Sub",  "Esc",  "Fs",   "Gs",   "Rs",   "Us",
  110.  
  111.     "Space", "ExclamationMark", "QuotationMark", "PoundSign",
  112.     "DollarSign", "PercentSign", "Andpersand", "Apostrophe",
  113.     "LeftParenthesis", "RightParenthesis", "Asterisk", "PlusSign",
  114.     "Comma", "Hyphen", "Period", "Slash",
  115.     "Zero", "One", "Two", "Three",
  116.     "Four", "Five", "Six", "Seven",
  117.     "Eight", "Nine", "Colon", "SemiColon", 
  118.     "LessThan", "Equal", "GreaterThan", "QuestionMark",
  119.  
  120.     "AtSign", "A", "B", "C", "D", "E", "F", "G",
  121.     "H", "I", "J", "K", "L", "M", "N", "O",
  122.     "P", "Q", "R", "S", "T", "U", "V", "W",
  123.  
  124.     "X", "Y", "Z", "LeftSquareBracket",
  125.     "BackSlash", "RightSquareBracket", "Caret", "UnderScore",
  126.  
  127.     "Accent", "a", "b", "c", "d", "e", "f", "g",
  128.     "h", "i", "j", "k", "l", "m", "n", "o",
  129.     "p", "q", "r", "s", "t", "u", "v", "w",
  130.  
  131.     "x", "y", "z", "LeftBrace",
  132.     "Bar", "RightBrace", "Tilde", "Del",
  133.  
  134.     "XNul",  "XSoh",  "XStx",  "XEtx",  "XEot",  "XEnq",  "XAck",  "XBel",
  135.     "XBs",   "XHt",   "XNl",   "XVt",   "XNp",   "XCr",   "XSo",   "XSi",
  136.     "XDle",  "XDc1",  "XDc2",  "XDc3",  "XDc4",  "XNak",  "XSyn",  "XEtb",
  137.     "XCan",  "XEm",   "XSub",  "XEsc",  "XFs",   "XGs",   "XRs",   "XUs",
  138.  
  139.     "XSpace", "XExclamationMark", "XQuotationMark", "XPoundSign",
  140.     "XDollarSign", "XPercentSign", "XAndpersand", "XApostrophe",
  141.     "XLeftParenthesis", "XRightParenthesis", "XAsterisk", "XPlusSign",
  142.     "XComma", "XHyphen", "XPeriod", "XSlash",
  143.     "XZero", "XOne", "XTwo", "XThree",
  144.     "XFour", "XFive", "XSix", "XSeven",
  145.     "XEight", "XNine", "XColon", "XSemiColon", 
  146.     "XLessThan", "XEqual", "XGreaterThan", "XQuestionMark",
  147.  
  148.     "XAtSign", "XA", "XB", "XC", "XD", "XE", "XF", "XG",
  149.     "XH", "XI", "XJ", "XK", "XL", "XM", "XN", "XO",
  150.     "XP", "XQ", "XR", "XS", "XT", "XU", "XV", "XW",
  151.  
  152.     "XX", "XY", "XZ", "XLeftSquareBracket",
  153.     "XBackSlash", "XRightSquareBracket", "XCaret", "XUnderScore",
  154.  
  155.     "XAccent", "Xa", "Xb", "Xc", "Xd", "Xe", "Xf", "Xg",
  156.     "Xh", "Xi", "Xj", "Xk", "Xl", "Xm", "Xn", "Xo",
  157.     "Xp", "Xq", "Xr", "Xs", "Xt", "Xu", "Xv", "Xw",
  158.  
  159.     "Xx", "Xy", "Xz", "XLeftBrace",
  160.     "XBar", "XRightBrace", "XTilde", "XDel"
  161.    };
  162.  
  163.     const characterG*
  164. characterG::ValueToCharacters[OATH_CHAR_CNT];
  165.  
  166.  
  167. //***************************************************************************
  168.